<?php
/**
 * 页面缓存 - JBlog
 * 
 * @copyright (c) 2008-2010 JBlog (www.lisijie.org)
 * @author lisijie <lisijie86@gmail.com>
 * @version $Id: class_cachepage.php 513 2010-06-22 02:02:08Z lisijie86 $
*/

class CachePage extends Cache {
	
	function CachePage() {
		$this->__construct();
	}
	
	function __construct() {
		$options = array(
			'expire' => config('cachetime'),
			'prefix' => '',
			'dir'    => 'page'
		);
		parent::__construct($options);
	}
	
	function filename($get) {
		$get['page'] = max(1, (int)$get['page']);
		switch ($get['mod']) {
			case 'index' :
				$dir = 'd_'.ceil($get['page'] / 500);
				$name = 'index/'.$dir.'/'.$get['page'];	
				break;
			case 'post' :
				$dir = 'd_'.($get['id']?ceil($get['id']/500):'alias');
				$name = 'post/'.$dir.'/'.($get['id']?$get['id']:$get['alias']);	
				break;
			case 'cate' :
				$dir = $get['id'] ? $get['id'] : $get['alias'];
				$name = 'cate/'.$dir.'/'.$get['page'];
				break;
		}
		$filename = $this->path.$name.'.php';
		if ( !is_dir(dirname($filename)) ) {
			make_dir(dirname($filename));
		}
		return $filename;
	}
}

function cache_footer() {
	global $db,$starttime,$_CACHE;
	$output = ob_get_contents();
	if ($_CACHE['config']['blog']['debug']) {
		$mtime = explode(' ',microtime());
		$stoptime = $mtime[0] + $mtime[1];
		$runtime = number_format($stoptime - $starttime, 6);
		$output .= "\n".'<script type="text/javascript">$("#run_info").html("Update at '.get_date('H:i:s', $GLOBALS['cache_update_time']).', Processed in '.$runtime.' second(s), '.$db->querynum.' queries, Gzip '.($_CACHE['config']['blog']['obstart'] ? 'enabled' : 'disabled').'");</script>';
	}
	obclean();
	echo $output;
	unset($output);
	exit;
}

?>